import java.util.*;
import java.io.FileInputStream;
import java.io.IOException;
import bbGraphs.*;
import GraphTest.*;

public class AdvPropTester 
{
	/**
	 * @param args
	 */
	public static void main( String[] args ) 
	{
		if( args.length < 1 )
		{
			System.out.println( "Usage: AdvPropTester <config file>" );
		}
		
		String configFileName = args[ ConfigConstants.CONFIG_FILE_ARG ];
		Properties config = new Properties();
		try
		{
			config.load( new FileInputStream( configFileName )  );
		} 
		catch( IOException e )
		{
			System.out.println( "Couln't find config file: " + configFileName );
			System.exit( -1 );
		}
		
		int numberOfGraphs = Integer.parseInt( config.getProperty( ConfigConstants.NUM_OF_GRAPHS ) );
		int initRedSelect = Integer.parseInt( config.getProperty( ConfigConstants.INITIAL_RED_SELECT ) );
		float activeEdgeProb = Float.parseFloat( config.getProperty( ConfigConstants.ACTIVE_EDGE_PROB ) );
		
		System.out.println( "Starting to load data...");
		GraphData.Graph.Builder gData = GraphData.Graph.newBuilder();
		
		try
		{
			gData.mergeFrom( new FileInputStream( args[ ConfigConstants.GRAPH_DATA ] ) );
		}
		catch( IOException e )
		{
			System.out.println( "Couln't load graph data: " + args[ ConfigConstants.GRAPH_DATA ] );
			System.exit( -1 );
		}
		
		System.out.println( "Finished loading graph data, now starting the graph" );
		
		Graph graphObj = new Graph();
		for( GraphData.Node node: gData.getNodesList() )
		{
			graphObj.addNode( node.getID(), new Node( node.getID() ) );
		}
		
		for( GraphData.Edge edge: gData.getEdgesList() )
		{
			graphObj.addEdge( edge.getSource(), edge.getTarget() );
		}
		
		GraphTester gTester = new GraphTester( graphObj, activeEdgeProb, initRedSelect, GraphTester.DEGREE_CENTRALITY, numberOfGraphs );
		int blueNodesNeeded = gTester.runTests();
	
		
		System.out.println( "Done" );
	}

}
